package vashion.azeroth.api.controller.item;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import vashion.azeroth.api.controller.base.BaseController;
import vashion.azeroth.contant.ForestErrorEnum;
import vashion.azeroth.core.item.pojo.PropertyMetaDO;
import vashion.azeroth.core.manager.forest.BasePropertyManager;
import vashion.azeroth.core.result.ApiResult;

import java.util.List;

/**
 * 属性维护
 *
 * @param <T>
 */
@Controller
@RequestMapping("/api/property")
public class PropertyController<T> extends BaseController {

    private final static Logger log = LoggerFactory.getLogger(PropertyController.class);

    @Autowired
    private BasePropertyManager basePropertyManager;

    /**
     * 获取属性列表
     *
     * @return
     */
    @RequestMapping("getPropertyList.htm")
    @ResponseBody
    public ApiResult<List<PropertyMetaDO>> getPropertyList(@ModelAttribute("PropertyMetaDO") PropertyMetaDO propertyMetaDO) {

        return basePropertyManager.getPropertyList(propertyMetaDO);
    }

    @RequestMapping("getPropertyDetail.htm")
    @ResponseBody
    public ApiResult<PropertyMetaDO> getPropertyDetail(long PropertyId) {

        if (PropertyId <= 0) {
            return ApiResult.newErrorResult(ForestErrorEnum.PROPERTY_ARG_ERROR.getErrorCode(), ForestErrorEnum.PROPERTY_ARG_ERROR.getErrorMessage());
        }
        return basePropertyManager.getDetail(PropertyId);
    }

}
